<?php 
## include required files
/*******************************/
require_once '../model/state.php';
/*******************************/
## Create Objects
/*******************************/
$stateObj = new Model_State();
/*******************************/

if(isset($_POST['editstate_btn'])) 
{
	
	## apply PHP validation for required filed
	if( $_POST['suburbname'] != '' && trim($_POST['postcode']) != '') {	
		extract($_POST);		
		$stateeditArray['suburb']   = return_post_value($_POST['suburbname']);		
		$stateeditArray['postcode']      = return_post_value($_POST['postcode']);		
		$stateObj->editPostalCodeById($stateeditArray,$_POST['postID']);
		$_SESSION['msg'] = "<div class='success_msg'><span>Postal code edited successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=postalcode&stateid='.$_GET['stateid'].'&page='.$_GET['page']);
		exit;
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please fill all required fields</span></div>';
	}
	// main if closed
}



if($_GET['id'] != ''&& $_GET['action'] == 'edit') {
	$postal_id = base64_decode($_GET['id']);
	$postDetArray = $stateObj->getPostalDetailsById($postal_id);	
	$smarty->assign('postDetArray', $postDetArray);
}

if($_GET['stateid'] != ''&& $_GET['action'] == 'edit') {
	$state_id = base64_decode($_GET['stateid']);
	$stateDetArray = $stateObj->getStateDetailsById($state_id);	
	$smarty->assign('stateDetArray', $stateDetArray);
}


## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'state');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($stateObj);



$smarty->display(TEMPLATEDIR_ADMIN. 'state/editpostalcode.tpl');
unset($smarty);
?>